package com.example.xgakj.mylibrary.mvp.utils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created by Administrator on 2017-08-22.
 */

public class MyInjectUtil {
    public static void inject(Object activity){
        Class clazz=activity.getClass();
        ContentView contentView = (ContentView) clazz.getAnnotation(ContentView.class);
        if (contentView!=null){
            int value = contentView.value();
            try {
                Method setContentView = clazz.getMethod("setContentView", int.class);
                setContentView.invoke(activity,value);
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }

    }
}
